﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Mimoza.Common;
using Mimoza.Transport;

namespace Mimoza.DBLayer.Transport
{
    public class UpdatesRepositoryCustomRequest
    {
        public enum CustomOperationType
        {
            None,
            GetUpdate,
            GetUpdates
        }

        public UpdatesRepositoryCustomRequest()
        {
        }

        public UpdatesRepositoryCustomRequest(CustomOperationType operationType)
        {
            Init(operationType, null);
        }

        public UpdatesRepositoryCustomRequest(CustomOperationType operationType,
            string argument1)
        {
            Init(operationType, argument1);
        }

        void Init(CustomOperationType operationType, string argument1)
        {
            OperationType = operationType;
            Argument1 = argument1;
        }

        public CustomOperationType OperationType = CustomOperationType.None;
        public string Argument1 = null;
    }

    public class UpdatesRepositoryTranferRequest :
        TransferObjectGeneric<UpdatesRepositoryTranferRequest, RepositoryReply<UpdateRecord>>
    {
        public UpdatesRepositoryTranferRequest()
        {
        }

        public UpdatesRepositoryTranferRequest(Operation oper, UpdateRecord record)
        {
            Request.Operation = oper;
            Request.Object = record;
        }

        public UpdatesRepositoryTranferRequest(UpdatesRepositoryCustomRequest customReq)
        {
            Request.Operation = Operation.Custom;
            Request.CustomRequest = customReq;
        }

        override public RepositoryReply<UpdateRecord> ProcessRequest()
        {
            return Request.Process(Connection, Repository) as RepositoryReply<UpdateRecord>;
        }

        public RepositoryRequest<
            UpdateRecord,
            ServerRepository<UpdateRecord, UpdatesRepositoryCustomRequest, IDBUpdateRepository>,
            UpdatesRepositoryCustomRequest,
            IDBUpdateRepository> Request = new RepositoryRequest<
                UpdateRecord,
                ServerRepository<UpdateRecord, UpdatesRepositoryCustomRequest, IDBUpdateRepository>,
                UpdatesRepositoryCustomRequest,
                IDBUpdateRepository>();

        public static ServerRepository<UpdateRecord, UpdatesRepositoryCustomRequest, IDBUpdateRepository> Repository = null;
    }
}
